package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.dto.PasswordEditDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import com.sky.vo.employee.EmployeeVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface EmployeeMapper {

    /**
     * 条件查询员工列表
     *
     * @param condition 查询条件
     * @return
     */
    Page<EmployeeVO> list(EmployeePageQueryDTO condition);

    /**
     * 新增员工
     *
     * @param employee 员工信息
     */
    @AutoFill(value = OperationType.INSERT)
    void add(Employee employee);

    /**
     * 更新员工
     *
     * @param employee
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据id删除员工
     *
     * @param id 要删除的员工id
     */
    @Delete("delete from employee where id=#{id}")
    void deleteById(Integer id);

    /**
     * 根据id获取员工
     *
     * @param id 要查询的员工id
     * @return
     */
    @Select("select * from employee where id=#{id}")
    Employee getById(Integer id);

    /**
     *  根据用户名查询员工信息
     * @param username 用户名
     * @return 员工信息
     */
    Employee getByUsername(String username);

    /**
     * 启用、禁用员工账号
     * @param status  账号的状态
     * @param id   员工的id
     */
    @Update("update employee set status=#{status} where id=#{id}")
    void updateStatus(Integer status, Integer id);

    /**
     * 修改密码
     * @param passwordEditDTO  新密码信息
     */
    @Update("update employee  set password=#{newPassword} where id=#{id}")
    void updatePassword(PasswordEditDTO passwordEditDTO);
}
